package pl.edu.pw.elka.tinyrepo.trash;

import java.util.Map;

import pl.edu.pw.elka.tinyrepo.common.WebDAVMethod;

/**
 * Klasa ułatwiająca budowanie zapytań do 
 * serwera WebDAV
 * 
 * @author Anna Stępień
 * @version 13-12-2011
 *
 */
public class RequestBuilder
{
	private final Map<String, String> headers;
	private final WebDAVMethod method;
	private final String protocol;
	private final String host;
	private final String path;
	
	
	public RequestBuilder(final WebDAVMethod method, final String protocol, 
			final String host, final String path, Map<String, String> headers)
	{
		this.method = method;
		this.protocol = protocol;
		this.host = host;
		this.path = path;
		this.headers = headers;
	}
	
	public final String build()
	{
		StringBuilder request = new StringBuilder();
		
		request.append(method.toString() + " " + path + " " + protocol + "\r\n");
		request.append("Host:" + host);
		
		for (Map.Entry<String, String> entry : headers.entrySet()) 
		{
			request.append(entry.getKey() + ": " + entry.getValue() + "\r\n");
		}
		
		request.append("\r\n");
		
		return request.toString();
	}
}
